package com.start.manager.controller;

import com.jienlee.common.common.RestResult;
import com.start.manager.domain.request.LoginParam;
import com.start.manager.enums.ResultCodeEnum;
import com.start.manager.service.IUserService;
import com.start.manager.util.MyUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登陆的控制类
 *
 * @author jian.li
 * @date 2019年 12月19日 13:53:28
 */
@RestController
public class LoginController {

    @Autowired
    private IUserService userService;

    @PostMapping(value = "/login")
    public RestResult<String> login(@RequestBody LoginParam loginParam) {
        RestResult<String> result = new RestResult<>();
        String token = userService.login(loginParam);
        if (StringUtils.isNotEmpty(token)) {
            return result.success(token);
        } else {
            return result.failed(ResultCodeEnum.USER_ERROR);
        }
    }

    public static void main(String[] args) {
        String s = MyUtil.encoderMD5("258258");
        System.out.println(s);
    }
}
